package com.zhangyu.shadow.repair.delegate.search;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.graphics.drawable.VectorDrawableCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zhangyu.shadow.repair.R;
import com.zhangyu.shadow.repair.config.StateCode;
import com.zhangyu.shadow.repair.delegate.bean.BusBean;

import java.util.List;

/**
 * Created by 张宇 on 2017/3/15.
 */

public class BusListAdapter extends BaseQuickAdapter<BusBean, BaseViewHolder> {
    private VectorDrawableCompat mDrawableCompatReady;
    private VectorDrawableCompat mDrawableCompatDoing;
    private VectorDrawableCompat mDrawableCompatComplete;
    private VectorDrawableCompat mDrawableChevron;
    private Drawable mReady;
    private Drawable mDoing;
    private Drawable mDone;

    public BusListAdapter(Context context, int layoutResId, List<BusBean> data) {
        super(layoutResId, data);
        mDrawableCompatReady = VectorDrawableCompat.create(context.getResources(),
                R.drawable.vector_drawable_bus_on_hand, context.getTheme());
        mDrawableCompatDoing = VectorDrawableCompat.create(context.getResources(),
                R.drawable.vector_drawable_bus_maintenance, context.getTheme());
        mDrawableCompatComplete = VectorDrawableCompat.create(context.getResources(),
                R.drawable.vector_drawable_bus_complete, context.getTheme());
        mDrawableChevron = VectorDrawableCompat.create(context.getResources(),
                R.drawable.ic_chevron_right_gray_24dp, context.getTheme());
        mReady = context.getResources()
                .getDrawable(R.drawable.ready_text);
        mDoing = context.getResources()
                .getDrawable(R.drawable.doing_text);
        mDone = context.getResources()
                .getDrawable(R.drawable.done_text);
    }

    @Override
    protected void convert(BaseViewHolder helper, BusBean item) {
        helper.addOnClickListener(R.id.card_view);
        helper.setText(R.id.tv_bus_number, item.getVehicleCode());
        helper.setText(R.id.tv_maintain_type, item.getMaintenanceTypeName());
        int code = item.getWorkStatus();
        helper.setVisible(R.id.layout_ready_work, false);
        switch (code) {
            case 4:
                helper.setImageDrawable(R.id.img_bus, mDrawableCompatDoing);
                helper.setImageDrawable(R.id.image_text, mDoing);
                break;
            case 5:
            case 6:
                helper.setImageDrawable(R.id.img_bus, mDrawableCompatComplete);
                helper.setImageDrawable(R.id.image_text, mDone);
                break;
            default:
                if (item.getWorkStatusCode().equals(StateCode.READY_WORK)) {
                    helper.setVisible(R.id.layout_ready_work, true);
                }
                helper.setImageDrawable(R.id.img_bus, mDrawableCompatReady);
                helper.setImageDrawable(R.id.image_text, mReady);
                break;
        }
        helper.setImageDrawable(R.id.iv_chevron, mDrawableChevron);
        helper.setText(R.id.tv_bus_line, item.getRouteName());
        helper.setText(R.id.tv_bus_plan_time, "计划保养时间:" + item.getPlanStartTime() + "-" + item.getPlanEndTime());
        String startTime = item.getActualStartTime();
        if (startTime == null || startTime.isEmpty() || "null".equals(startTime)) {
            startTime = "未开始";
        }
        helper.setText(R.id.tv_bus_actual_start_time, "作业开始时间:" + startTime);

        String endTime = item.getActualEndTime();
        if (endTime == null || endTime.isEmpty() || "null".equals(endTime)) {
            endTime = "未完成";
        }
        helper.setText(R.id.tv_bus_actual_end_time, "作业完成时间:" + endTime);

    }

}
